package com.oocl.sender;

import java.util.List;

import javax.jms.JMSException;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.oocl.pojo.Book;
import com.oocl.ptp.Producer;

/**
 * Hello world!
 * 
 */
public class BookJsonSender {

	private List<Book> books;
	private Producer producer;

	public BookJsonSender(List<Book> books,String queueName) throws JMSException {
		this.producer = new Producer(queueName);
		this.books = books;
	}

	public void sendJsonToQueue() throws Exception {

		ObjectMapper mapper = new ObjectMapper();
		for (int i = 0; i < books.size(); i++) {
			String s = mapper.writeValueAsString(books.get(i));
			producer.sendMsg(s);
		}

	}

}
